/*
 * @Author: 西索酱
 * @Date: 2021-07-04 10:02:12
 * @LastEditTime: 2021-07-05 08:32:17
 * @LastEditors: 西索酱
 * @Description: 
 * @FilePath: \snake_demo2\代码\vscripts\game_mode.ts
 * 你也在看我的代码吗？
 */
import { reloadable } from "./lib/tstl-utils";
import { Console } from './console';

const heroSelectionTime = 10;

declare global {
    interface CDOTAGamerules {
        Addon: GameMode;
        log:(msg:string)=>void;
    }
    
}
@reloadable
export class GameMode {
    mode :CDOTABaseGameMode

    public static Precache(this: void, context: CScriptPrecacheContext) {
        PrecacheResource("particle", "particles/units/heroes/hero_meepo/meepo_earthbind_projectile_fx.vpcf", context);
        PrecacheResource("soundfile", "soundevents/game_sounds_heroes/game_sounds_meepo.vsndevts", context);
    }

    public static Activate(this: void) {
        GameRules.Addon = new GameMode();
        GameRules.log = (new Console()).log
    }

    constructor() {
        this.mode = GameRules.GetGameModeEntity()
        this.configure();
        ListenToGameEvent("game_rules_state_change", () => this.OnStateChange(), undefined);
        ListenToGameEvent("npc_spawned", event => this.OnNpcSpawned(event), undefined);
        CustomGameEventManager.RegisterListener('c2s_test_event',(id,event)=>print('你点击了测试按钮'))
    }

    private configure(): void {
        
        GameRules.SetCustomGameTeamMaxPlayers(DOTATeam_t.DOTA_TEAM_GOODGUYS, 3);
        GameRules.SetCustomGameTeamMaxPlayers(DOTATeam_t.DOTA_TEAM_BADGUYS, 3);

        GameRules.SetCustomGameSetupAutoLaunchDelay(0)
        GameRules.SetShowcaseTime(0);
        GameRules.SetHeroSelectionTime(heroSelectionTime);
        this.mode.SetCustomGameForceHero('npc_dota_hero_axe')
    }

    public OnStateChange(): void {
    }
    public Reload() {
        print("Script reloaded!");
    }

    private OnNpcSpawned(event: NpcSpawnedEvent) {
        let npc = EntIndexToHScript(event.entindex) as CDOTA_BaseNPC
        GameRules.log(`出生事件 ${npc.GetUnitName()}`)
    }
}